/*
 * Project: SpringCloudDemo-BUS-RabbitMQ
 * 
 * File Created at 2017年2月13日
 * 
 * Copyright 2016 CMCC Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * ZYHY Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license.
 */
package com.lucky.producer;

import com.lucky.share.Message;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Type Sender.java
 * @Desc 
 * @author hadoop
 * @date 2017年2月13日 下午3:47:04
 * @version 
 */
@Component
@EnableScheduling
public class Sender {
    
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Bean
    public Sender mySender() {
        return new Sender();
    }

    @Bean
    public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
        RabbitTemplate template = new RabbitTemplate(connectionFactory);
        template.setMessageConverter(new Jackson2JsonMessageConverter());
        return template;
    }

    @Scheduled(fixedDelay = 1000L)
    public void send() {
        Message message = new Message();
        message.setContent("内容");
        message.setId(112121);
        this.rabbitTemplate.convertAndSend("mqqueue", message);
    }

    /*class Message {
        private long id;
        private String content;

        public long getId() {
            return id;
        }

        public void setId(long id) {
            this.id = id;
        }

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }
    }*/
}




/**
 * Revision history
 * -------------------------------------------------------------------------
 * 
 * Date Author Note
 * -------------------------------------------------------------------------
 * 2017年2月13日 hadoop creat
 */